import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';

class CustomSearchDelegate extends SearchDelegate {
  // 输入框后面的按钮
  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
          onPressed: () {
            print('清空输入框');
          },
          icon: const Icon(
            Icons.arrow_back,
            color: Color.fromARGB(255, 209, 0, 63),
          ))
    ];
  }

  // 搜索框前面的按钮样式
  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
        onPressed: () {
          print('点击');
        },
        icon: const Icon(
          Icons.arrow_back,
          color: Color.fromARGB(255, 209, 0, 63),
        ));
  }

  //搜素结果
  @override
  Widget buildResults(BuildContext context) {
    return ListView.separated(
        itemBuilder: (context, index) {
          return ListTile(
            onTap: () {
              print(query);
            },
          );
        },
        separatorBuilder: (BuildContext context, int int) {
          return const Divider();
        },
        itemCount: 10);
  }

  // 搜索的建议结果
  @override
  Widget buildSuggestions(BuildContext context) {
    return ListView();
  }
}

class Search extends StatefulWidget {
  const Search({Key? key}) : super(key: key);
  @override
  State<Search> createState() => _SearchState();
}

class _SearchState extends State<Search> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        showSearch(context: context, delegate: CustomSearchDelegate());
      },
    );
  }
}
